package com.smi.cn.satemachine;

import com.smi.cn.satemachine.ReturnVo.RmaStatus;
import com.smi.cn.satemachine.ReturnVo.RmaTrigger;
import org.springframework.context.ApplicationContext;
import org.squirrelframework.foundation.fsm.annotation.State;
import org.squirrelframework.foundation.fsm.annotation.StateMachineParameters;
import org.squirrelframework.foundation.fsm.annotation.States;
import org.squirrelframework.foundation.fsm.annotation.Transit;
import org.squirrelframework.foundation.fsm.annotation.Transitions;

/**
 * Created by zhangyanfei on 2017/7/26.
 * from to 1
 *            when
 *         2
 * @author zhangyanfei
 * @date 2017/07/26
 */
@StateMachineParameters(stateType = RmaStatus.class, eventType = RmaTrigger.class,
    contextType = StateMachineContext.class)
@States({
    @State(name = "PENDING", initialState = true),
    @State(name = "CONFIRMING",entryCallMethod = "complete"),
    @State(name = "REJECTED"),
    @State(name = "RETURNING"),
    @State(name = "REFUND_APPROVING"),
    @State(name = "RETURNED_CONFIRMING"),
    @State(name = "REFUND_APPROVED"),
    @State(name = "REFUND_FINISHED", entryCallMethod = "complete"),
    @State(name = "CANCELED")
})
@Transitions({
    @Transit(from = "PENDING", to = "CONFIRMING", on = "APPLY_CONFIRM",callMethod = "test",transDesc = "测试01"),
    @Transit(from = "PENDING", to = "CANCELED", on = "CANCEL",callMethod = "test",transDesc = "测试02"),
})
public class TestMachine extends BaseReturnMachine{

    /**
     * 依赖的对象
     *
     * @param applicationContext
     */
    public TestMachine(ApplicationContext applicationContext) {
        super(applicationContext);
    }
    public void test(RmaStatus fromState, RmaStatus toState, RmaTrigger event,
                     StateMachineContext stateMachineContext){
        System.out.println("Hello Statemachine!");
    }

    public void complete(RmaStatus fromState, RmaStatus toState, RmaTrigger event,
                         StateMachineContext stateMachineContext){
        System.out.println("complete");
    }
}
